package com.neu.tlias.controller;


import com.neu.tlias.pojo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class Session {

//    @GetMapping("/s1")
//    public Result session1(HttpSession session){
//        session.setAttribute("loginUser","Jack");
//        return Result.success();
//    }

    @GetMapping("/s1")
    public Result session1(HttpServletRequest request){
        request.getSession().setAttribute("loginUser","Jack");
        return Result.success();
    }

    @GetMapping("/s2")
    public Result session2(HttpServletRequest request){
        //HttpSession session = request.getSession();
        Object loginUser = request.getSession().getAttribute("loginUser");
        return Result.success(loginUser);
    }
}
